#@layout()

#define content()

<div class="easyui-layout" data-options="fit:true">
    <div data-options="region:'center',border:true">
        <div id="datagridId"></div>

        <div id="datagridTb">
            <div class="row">
                <div class="col-md-12">
                    <form id="searchForm">
                        <div class="easyui-panel" title="信息查询" style="width:100%;padding:10px;"
                             data-options="iconCls:'icon-application_form'">

                            #(_res.get('user.form.username')): <input class="easyui-textbox" id="userName" style="width:200px">&nbsp;&nbsp;
                            #(_res.get('user.form.email')): <input class="easyui-textbox" id="email" style="width:200px">&nbsp;&nbsp;
                            #(_res.get('user.form.phone')): <input class="easyui-numberbox" id="phone" style="width:200px">&nbsp;&nbsp;

                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="datagridQuery();" iconCls="icon-zoom">#(_res.get('system.common.search'))</a>
                            <a href="javascript:;" class="easyui-linkbutton" data-options="plain:true" onclick="$('#searchForm').form('clear');" iconCls="icon-zoom_out">#(_res.get('system.common.clear'))</a>
                        </div>
                    </form>
                </div>
                <div class="row">
                    <div class="col-md-12" style="padding: 5px 25px;">
                        #for(resource : resourceList)
                        <a href="javascript:;" class="easyui-linkbutton" data-options="iconCls:'#(resource.icon)',plain:true" id='#(resource.url)'>#(_res.get(resource.resourceName))</a>
                        #end
                    </div>
                </div>
            </div>
        </div>
    </div>




</div>

#end


#define css()

#end


#define js()


<script type="text/javascript" src="#(ctx)/static/js/crypto-js.js"></script>

<script type="text/javascript">
    var _datagrid = "datagridId", _form = "formId", _datagridTb = "datagridTb";
    var datagridListUrl = contextRootPath + '/user/list';

    $(function () {

        //初始化表格
        $("#" + _datagrid).datagrid({
            url: datagridListUrl,
            fit: true,
            border: false,
            rownumbers: true,
            pageSize: 30,
            toolbar: '#' + _datagridTb,
            singleSelect: false,
            pagination: true,
            nowrap: false,
            striped: true,
            fitColumns: true,
            columns: [[
                {field: DBConts.TABLE_USER.USER_ID, title: DBConts.TABLE_USER.USER_ID, width: 100, checkbox: true},
                {
                    field: DBConts.TABLE_USER.USER_NAME,
                    title: "#(_res.get('user.form.username'))",
                    sortable: true
                }, {
                    field: DBConts.TABLE_USER.EMAIL,
                    title: "#(_res.get('user.form.email'))",
                    sortable: true
                }, {
                    field: DBConts.TABLE_USER.PHONE,
                    title: "#(_res.get('user.form.phone'))",
                    sortable: true
                }, {
                    field: 'rolenames',
                    title: "#(_res.get('role.form.name'))",
                    sortable: true
                }, {
                    field: DBConts.TABLE_USER.DES,
                    title: "#(_res.get('user.form.des'))",
                    sortable: true
                }, {
                    field: 'createts',
                    title: "#(_res.get('user.form.creates'))",
                    sortable: true
                }
            ]]
        });


    #for(resource : resourceList)

         #if(resource.url == 'user_add')

            $("##(resource.url)").on('click', function () {
                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 700;
                params.height = 450;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-application_add';
                params.url = contextRootPath + '/user/add';
                params.buttons = [{
                    text: '提交',
                    iconCls: 'icon-application_go',
                    handler: function () {
                        datagrid_save('add');
                    }
                }, {
                    text: '重置',
                    iconCls: 'icon-application_side_contract',
                    handler: function () {
                        clearForm('formId')
                    }
                }];

                crud_dlg(params);
            });

         #elseif(resource.url == 'user_edit')

            $("##(resource.url)").on('click', function () {
                var selected = $('#' + _datagrid).datagrid('getSelected');


                if (selected == null) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    return;
                }

                var selections = $('#' + _datagrid).datagrid('getSelections');

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    return;
                } else if (selections.length > 1) {
                    $.messager.alert("提示框", "编辑的用户为多个，请重新选择!", "warning");
                    return;
                }

                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 700;
                params.height = 400;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-application_edit';
                params.url = contextRootPath + '/user/edit/' + selected[DBConts.TABLE_USER.USER_ID];
                params.buttons = [{
                    text: '提交',
                    iconCls: 'icon-application_go',
                    handler: function () {
                        datagrid_save();
                    }
                }, {
                    text: '关闭',
                    iconCls: 'icon-application_side_contract',
                    handler: function () {
                        $('#crud_dlg').dialog('close');
                    }
                }];

                crud_dlg(params);
            });

        #elseif(resource.url == 'user_remove')

            $("##(resource.url)").on('click', function () {
                var selections = $('#' + _datagrid).datagrid('getSelections');
                var ids = "";
                var names = "";

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    return;
                }

                $.messager.confirm('确认框', '请确定需要删除所选择的用户么？', function (r) {
                    if (r) {
                        $.each(selections, function (i, v) {
                            ids += v[DBConts.TABLE_USER.USER_ID] + ",";
                            names += v[DBConts.TABLE_USER.USER_NAME] + ",";
                        });

                        $.post(contextRootPath + "/user/remove/" + ids + "-" + names, function (data) {
                            var params = {};
                            params.element = _datagrid;
                            params.data = data;
                            params.isClose = false;
                            resultCallback(params);
                        }, 'json');
                    }
                });


            });

        #elseif(resource.url == 'user_resetpwd')

            $("##(resource.url)").on('click', function () {
                var selections = $('#' + _datagrid).datagrid('getSelections');
                var ids = "";

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    ;
                    return;
                }

                $.messager.confirm('确认框', '请确定需要对所选用户进行密码重置吗?', function (r) {
                    if (r) {
                        $.each(selections, function (i, v) {
                            ids += v[DBConts.TABLE_USER.USER_ID] + ",";
                        });

                        $.post(contextRootPath + "/user/resetpwd/" + ids, function (data) {
                            var params = {};
                            params.element = _datagrid;
                            params.data = data;
                            params.isClose = false;
                            resultCallback(params);
                        }, 'json');
                    }
                });
            });
        #elseif(resource.url == 'user_privileges')

            $("##(resource.url)").on('click', function () {
                var selected = $('#' + _datagrid).datagrid('getSelected');


                if (selected == null) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    return;
                }

                var selections = $('#' + _datagrid).datagrid('getSelections');

                if (selections.length < 1) {
                    $.messager.alert("提示框", "请选择需要操作的用户!", "warning");
                    return;
                } else if (selections.length > 1) {
                    $.messager.alert("提示框", "编辑的用户为多个，请重新选择!", "warning");
                    return;
                }

                var params = {};
                params.title = "#(_res.get(resource.resourceName))";
                params.width = 700;
                params.height = 250;
                params.top = '10px';
                params.modal = true;
                params.iconCls = 'icon-application_edit';
                params.url = contextRootPath + '/user/privileges/' + selected[DBConts.TABLE_USER.USER_ID];
                params.buttons = [{
                    text: '提交',
                    iconCls: 'icon-application_go',
                    handler: function () {
                        privileges();
                    }
                }];

                crud_dlg(params);
            });
            #end
        #end

    });


    function datagridQuery() {
        var userName = $("#userName");
        var email = $("#email");
        var phone = $("#phone");

        var flag = $("#searchForm").form('enableValidation').form('validate');

        if (!flag) return;

        $("#" + _datagrid).datagrid({
            queryParams: {
                "user.user_name": userName.val(),
                "user.email": email.val(),
                "user.phone": phone.val()
            }
        });
    }


    function checkSuperManagerForRole(checkBox) {
        if (($(checkBox).val() === SYSTEM_CONST.SUPER_MANAGER_ID) && ($(checkBox).is(':checked'))) {
            $.messager.alert("提示框", "超级管理员权限超大，请慎重选择!", "warning");
        }
    }

</script>

#end



